<?php defined('BASEPATH') OR exit('No direct script access allowed');

	class tipoftheday_class extends CI_Model {
	
		public function get_tipoftheday($post){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intID'=>$intID));
			} else {
				$intNumDays = stripslashes(filter_var($post['intNumDays'], FILTER_SANITIZE_STRING));
				$this->db->where(array('intNumDays'=>$intNumDays));
			}
			
			$query = $this->db->get_where('jtn_tipoftheday',array('intDisabled'=>0))->result_array();
			$query = current($query);
			
			if(trim($query['intID'])=="") {
				return 0;
			} else {
				return $query;
			}
		}
		public function list_tipoftheday(){
			if(isset($post['intID'])){
				$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
				$this->db->order_by("intID", "asc");
				$query = $this->db->get_where('jtn_tipoftheday',array('intDisabled'=>0,'intID'=>$intID));
			} else {
				$this->db->order_by("intID", "asc");
				$query = $this->db->get_where('jtn_tipoftheday',array('intDisabled'=>0));
			}
			if ($query->num_rows() > 0){
				$result = $query->result_array();
				return $result;
			}
			else{
				return 0;
			}
		}	
		public function delete($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'intDisabled' => 1,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_tipoftheday', $data);
		
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}		
		public function update($post){
			$intID = stripslashes(filter_var($post['intID'], FILTER_SANITIZE_STRING));
			$intNumDays = stripslashes(filter_var($post['intNumDays'], FILTER_SANITIZE_STRING));
			$strNote = stripslashes(filter_var($post['strNote'], FILTER_SANITIZE_STRING));
			$intFontSize = stripslashes(filter_var($post['intFontSize'], FILTER_SANITIZE_STRING));
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
		
			$data = array(
					'strNote' => $strNote,
					'intFontSize' => $intFontSize,
					'intNumDays' => $intNumDays,
					'strImgLink' => $strImgLink,
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->where(array('intID'=>$intID));
			$this->db->update('jtn_tipoftheday', $data);
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}		
		
		public function insert($post){
			$strImgLink = stripslashes(filter_var($post['strImgLink'], FILTER_SANITIZE_STRING));
			$intFontSize = stripslashes(filter_var($post['intFontSize'], FILTER_SANITIZE_STRING));
			$strNote = $post['strNote'];
				
			$data = array(
					'strImgLink' => $strImgLink,
					'strNote' => $strNote,
					'intFontSize' => $intFontSize,
					'intDisabled' => 0,
					'strCreatedby'=>$this->session->userdata('intID'),
					'dateCreatedDate'=>date('Y-m-d H:i:s'),
					'strModifiedBy'=>$this->session->userdata('intID'),
					'dateModifiedDate'=>date('Y-m-d H:i:s')
			);
		
			$this->db->insert('jtn_tipoftheday', $data);
				
			$this->db->where(array('intID'=>$this->db->insert_id()));
			$this->db->update('jtn_tipoftheday', array('intNumDays'=>$this->db->insert_id()));
			//$message['qry']=$this->db->last_query();
			if($this->db->_error_number()==0)
			{
				$message['fail'] = 0;
				$message['class'] = "success";
				$message['message'] = "Successfully saved.";
				$message['intID'] = $this->db->insert_id();
			}
			else
			{
				$message['fail'] = 1;
				$message['class'] = "error";
				$message['message'] = $message['message'].$this->db->_error_message();;
			}
			return $message;
		}		
	} // end class
?>